// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/testing/gtest_utils.h>
#include <pollux/common/config/config.h>
#include <pollux/connectors/hive/storage_adapters/s3fs/S3FileSystem.h>

#include <gtest/gtest.h>

namespace kumo::pollux {
namespace {

TEST(S3FileSystemFinalizeTest, finalize) {
  auto s3Config = std::make_shared<config::ConfigBase>(
      melon::F14FastMap<std::string, std::string>());
  ASSERT_TRUE(filesystems::initializeS3());
  ASSERT_FALSE(filesystems::initializeS3());
  {
    filesystems::S3FileSystem s3fs("", s3Config);
    POLLUX_ASSERT_THROW(
        filesystems::finalizeS3(), "Cannot finalize S3 while in use");
  }
  filesystems::finalizeS3();
  POLLUX_ASSERT_THROW(
      filesystems::initializeS3(),
      "Attempt to initialize S3 after it has been finalized.");
}

} // namespace
} // namespace kumo::pollux
